package com.xiyu.service.service.mailbox;

import cn.hutool.core.exceptions.ExceptionUtil;
import com.xiyu.service.model.mailbox.mail.MailboxMailErrorLogDraft;
import com.xiyu.service.repository.mailbox.mail.MailboxMailErrorLogRepository;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;

@Service
@Validated
public class MailboxMailErrorLogServiceImpl implements MailboxMailErrorLogService {

    @Resource
    MailboxMailErrorLogRepository mailboxMailErrorLogRepository;


    @Override
    public void saveMailErrorInfo(Long accountId, Long folderId, Long mailId, String uid, Exception e){
        mailboxMailErrorLogRepository.insert(MailboxMailErrorLogDraft.$.produce(draft ->
                draft.setAccountId(accountId).setMessage(e.getMessage())
                        .setFolderId(folderId).setMailId(mailId).setUid(uid)
                        .setStackTraceInfo(ExceptionUtil.stacktraceToString(e, 30000))
        ));
    }
}
